using System;
using Adoor.Expression.AST;

namespace Adoor.Expression
{
	/// <summary>
	/// ExpressionRemapper perform aliasing task..
	/// </summary>
	public class ExpressionRemapper : ExpressionCloner
	{
		private string newQualifier;
		public static ExpressionNode ReplaceNameQualifer(ExpressionNode n, string newQualifier)
		{
			ExpressionRemapper es = new ExpressionRemapper( newQualifier);
			n.Accept(es);
			return es.result;
		}

		protected ExpressionRemapper(string newQualifier)
		{
			this.newQualifier = newQualifier;
		}

		public override void VisitName(ExpressionName n)
		{
			if(newQualifier != null)
			{
				this.result = new ExpressionName(newQualifier, n.Value);
			}
			else
				base.VisitName(n);
		}
	}
}
